/**
 * @param {number[]} nums
 * @return {number}
 */
var pivotIndex = function (nums) {
    let sumLeft = 0
    let totalSum = nums.reduce((a, b) => a + b)
    for (let i = 0; i < nums.length; i++) {
        if (sumLeft === totalSum - sumLeft - nums[i]) {
            return i
        }
        sumLeft += nums[i]
    }
    return -1
};
console.log(pivotIndex([1, 7, 3, 6, 5, 6])); // Output: 3
console.log(pivotIndex([1, 2, 3]));          // Output: -1
console.log(pivotIndex([2, 1, -1]));         // Output: 0